﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WebSiteAdminTool.UI.Utils.Commands
{
    public class GenericCommand : ICommand
    {
        #region private data

        private Action<object> _handler = null;
        private bool _isEnabled = true;

        #endregion

        #region ctors

        public GenericCommand(Action<object> handler, bool enabled = false)
        {
            _handler = handler;
            _isEnabled = enabled;
        }

        #endregion

        #region public props

        public bool IsEnabled
        {
            get { return _isEnabled; }
            set
            {
                _isEnabled = value;
                if (CanExecuteChanged != null)
                {
                    CanExecuteChanged(this, EventArgs.Empty);
                }
            }
        }

        #endregion

        #region ICommand implementation

        public event EventHandler CanExecuteChanged;
        public void Execute(object parameter)
        {
            if (null != _handler)
                _handler(parameter);
        }

        public bool CanExecute(object parameter)
        {
            return IsEnabled;
        }
        
        #endregion
    }
}
